package hopital.report;

import hopital.sql.SqlDatabase;
import java.util.HashMap;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;

public class Report extends javax.swing.JDialog {

    private JasperPrint jasperPrint;

    public Report(final String file, final int id) {
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                HashMap parameters = new HashMap<>();
                parameters.put("p_id", id);
                parameters.put("p_image", (("logo.png")));
                try {
                    JasperReport report = (JasperReport) JRLoader.loadObject((getClass().getResourceAsStream(file)));
                    jasperPrint = JasperFillManager.fillReport(report, parameters, SqlDatabase.getDatabase().getConnection());
                    view1 = new View(jasperPrint);
                } catch (Exception ex) {
                    
                }
                initComponents();
                Report.this.setModal(true);
                Report.this.setLocationRelativeTo(null);
                Report.this.setVisible(true);
            }
        };
        Thread thread=new Thread(runnable);
        thread.start();
    }

    @SuppressWarnings("unchecked")
    private void initComponents() {//GEN-BEGIN:initComponents

        view1 = new View(jasperPrint);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setIconImage(new javax.swing.ImageIcon(getClass().getResource("/hopital/icon/group41.png")).getImage());
        setIconImages(null);
        setType(java.awt.Window.Type.UTILITY);

        view1.setPreferredSize(new java.awt.Dimension(450, 500));
        getContentPane().add(view1, java.awt.BorderLayout.CENTER);

        pack();
    }//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private hopital.report.View view1;
    // End of variables declaration//GEN-END:variables
}
